package com.ksl.kinglockguard.data;
import android.content.Context;
import android.text.TextUtils;

import com.lsk.open.core.MyLog;
import com.lsk.open.core.share_preference.BaseSharePreference;

public class SharePreferenceSdkData extends BaseSharePreference{	
	final static String FIRST_UPLOAD="first_upload";
	final static String FIRST_LANUCHER_UPLOAD="lanucher_times";
	final static String LANUCHER_DAY_UPLOAD="lanucher_upload";
	final static String APPS_UPLOADED="apps_uploaded";
	final static String APPS_UPLOAD_TIME="apps_upload_time";
	private final static String ERRORREPORT_RETRY_TIMES="error_report_times";
	public static void setFirstRegister(Context context ,boolean flag){
		setBoolean(context,FIRST_UPLOAD,flag);
	}
	
	public static boolean isFirstRegister(Context context){
		return getBoolean(context,FIRST_UPLOAD, false);
	}
	
	public static void setLanucherTimers(Context context,long oneTime){
		if(oneTime==-1){
			setString(context,FIRST_LANUCHER_UPLOAD,"");
			return;
		}
		String prex=getString(context, FIRST_LANUCHER_UPLOAD, "");
		if(prex.equals(""))
		setString(context,FIRST_LANUCHER_UPLOAD,oneTime+"");
		else{
			StringBuffer sb=new StringBuffer(prex);
			sb.append(",");
			sb.append(oneTime);
			setString(context,FIRST_LANUCHER_UPLOAD,sb.toString());
		}
	
	}
	
	
	public static String getLanucherTimers(Context context){
		return getString(context, FIRST_LANUCHER_UPLOAD, "");
	}
	
	public static void setUploadTwoDay(Context context ,long oneDay){
		setLong(context,LANUCHER_DAY_UPLOAD,oneDay);
	}
	
	public static long getUploadTwoDay(Context context){
		return getLong(context,LANUCHER_DAY_UPLOAD,0);
	}
	
	
	public static void setUploadAppsTime(Context context ,long oneDay){
		setLong(context,APPS_UPLOAD_TIME,oneDay);
	}
	
	public static long getUploadAppsTime(Context context){
		return getLong(context,APPS_UPLOAD_TIME,0);
	}
	
	public static void setUploadedContent(Context context ,String content){
		String old=	getUploadedContent(context);
		setString(context,APPS_UPLOADED,old+content);
	}
	
	public static String getUploadedContent(Context context ){
		return getString(context,APPS_UPLOADED,"");
	}

	
	public static long getErrorReportRTTimes(final Context context) {
		return getAppPreferences(context).getLong(ERRORREPORT_RETRY_TIMES, 0);
	}

	public static void setErrorReportRTTimes(final Context context, long times) {
		setLong(context, ERRORREPORT_RETRY_TIMES, times);
	}
	
	final static String SHOTCUT="Shortcut_time";
	public static void setShortcut(Context context ,long time){
		setLong(context,SHOTCUT,time);
	}
	
	public static long isShortcut(Context context){
		return getLong(context,SHOTCUT, 0);
	}

	private static final String LAST_CHECK_UPDATE_TIME = "last_check_update_time";
	public static long getLastCheckUpdateTime(Context context) {
		return getLong(context,LAST_CHECK_UPDATE_TIME, 0);
	}
	public static void setLastCheckUpdateTime(Context context, long time) {
		MyLog.i("UploadData","UploadData ------- setLastCheckUpdateTime -----time: " + time);
		setLong(context,LAST_CHECK_UPDATE_TIME,time);
	}
	private static final String IS_HOME_KEY_PRESSED = "is_home_key_pressed";
	public static Boolean getHomeKeyState(Context context) {
		return getBoolean(context,IS_HOME_KEY_PRESSED, false);
	}
	public static void setHomeKeyState(Context context, boolean pressed) {
		setBoolean(context,IS_HOME_KEY_PRESSED,pressed);
	}
	
	private static final String LAST_UPLOAD_USER_HABIT = "last_upload_user_habit";
	public static long getLastUploadUserHabit(Context context) {
		return getLong(context, LAST_UPLOAD_USER_HABIT, 0);
	}
	public static void setLastUploadUserHabit(Context context, long time) {
		setLong(context, LAST_UPLOAD_USER_HABIT, time);
	}
	
	private static final String LAST_UPLOAD_LIFE_STATUS = "last_upload_life_status";
	public static long getLastUploadLifeStatus(Context context) {
		return getLong(context, LAST_UPLOAD_LIFE_STATUS, 0);
	}
	public static void setLastUploadLifeStatus(Context context, long time) {
		setLong(context, LAST_UPLOAD_LIFE_STATUS, time);
	}
	private static final String FIRST_UPLOAD_START = "first_upload_start";
	public static long getFirstStartUpload(Context context) {
		return getLong(context, FIRST_UPLOAD_START, 0);
	}
	public static void setFirstStartUpload(Context context, long time) {
		setLong(context, FIRST_UPLOAD_START, time);
	}
	
	private static final String LAST_UPLOAD_LAUNCHER_TIMES = "last_upload_launcher_times";
	public static void setLastUploadLauncherTimes(Context context, long time) {
		setLong(context, LAST_UPLOAD_LAUNCHER_TIMES, time);
	}
	public static long getLastUploadLauncherTimes(Context context) {
		return getLong(context, LAST_UPLOAD_LAUNCHER_TIMES, 0);
	}
	
	
//	private static final String NEED_TO_STARTSERVICE="server_dispatch_ok";
//	
//	public static void setNeedToStartService(Context context ,boolean isNeed){
//	setBoolean(context, NEED_TO_STARTSERVICE, isNeed);	
//	}
//	
//	public static boolean isNeedToStartService(Context context){
//		return getBoolean(context, NEED_TO_STARTSERVICE, true);
//	}
	private static final String SCREEN_LOCK_FLAG="screen_lock_flag";
	
	public static void setScreenLockFlag(Context context ,boolean flag){
		setBoolean(context, SCREEN_LOCK_FLAG, flag);	
	}
	
	public static boolean getScreenLockFlag(Context context){
		return getBoolean(context, SCREEN_LOCK_FLAG, false);
	}
	
	
	private static final String WIFI_LOADPIC_LOAD="is_wifi_setting";
	public static void setWifiLoadPic(Context context ,boolean isNeed){
	setBoolean(context, WIFI_LOADPIC_LOAD, isNeed);	
	}
	//用于wifi开关
	public static boolean isWifiLoadPic(Context context){
		return getBoolean(context, WIFI_LOADPIC_LOAD, false);
	}
	
	//记录桌面壁纸加载完成开关

	private static final String DESK_PICTURE_LOADED_NUM = "desk_picture_load";
	public static int getTodayDeskPictureNum(Context context) {
		return getInt(context,DESK_PICTURE_LOADED_NUM, -1);
	}
	public static void setTodayDeskPictureNum(Context context, int  time) {
		setInt(context,DESK_PICTURE_LOADED_NUM,time);
	}
	private static final String DESK_PICTURE_LOADED_NUM_NEW = "desk_picture_load_new";
	public static int getTodayDeskPictureIndex(Context context) {
		return getInt(context,DESK_PICTURE_LOADED_NUM_NEW, -1);
	}
	public static void setTodayDeskPictureIndex(Context context, int  time) {
		setInt(context,DESK_PICTURE_LOADED_NUM_NEW,time);
	}
	
	final static String CACHE_APPID = "cache_appid";
	//缓存未统计成功的下载appid
	public static void cacheDownloadAppid(Context context,String appId){
		if(TextUtils.isEmpty(appId)){
			return;
		}
		String cache = getString(context, CACHE_APPID, "");
		cache = TextUtils.isEmpty(cache)?(appId+":"+System.currentTimeMillis()/1000):(cache+"|"+appId+":"+System.currentTimeMillis()/1000);
		setString(context, CACHE_APPID, cache);
	}
	//获取未统计成功的下载appid
	public static String getCacheDownloadAppid(Context context){
		return getString(context, CACHE_APPID,"");
	}
	
	//缓存上传服务器成功后需要清空原来缓存的数据
	public static void clearCacheAppId(Context context){
		setString(context, CACHE_APPID, "");
	}
	
	
	//是否需要遍历完所有数据的开关
	private static final String TRAVERSAL = "traversal";
	public static void setTraversalSwitch(Context context, int traversalSwitch){
		setInt(context, TRAVERSAL, traversalSwitch);
	}
	
	public static boolean getTraversalSwitch(Context context){
		return getInt(context, TRAVERSAL, 1) == 1;
	}
	
	//请求服务器的间隔时间
	private static final String INTERVALTIME = "interval_time";
	public static void setIntervalTime(Context context, long time){
		setLong(context, INTERVALTIME, time);
	}
	
	public static long getIntervalTime(Context context){
		return getLong(context, INTERVALTIME, 60*60*1000);
	}
	
	//展现h5游戏入口的时间间隔
	private static final String H5_ICON_DAYS = "h5_icon_time";
	public static void setH5IconDays(Context context, int time){
		setInt(context, H5_ICON_DAYS, time);
	}
	
	public static int getH5IconDays(Context context){
		return getInt(context, H5_ICON_DAYS, 0);
	}

	//本地的内容条数是否全部显示了一遍
	private static final String ISLOADED = "isloaded";
	public static void setIsLoaded(Context context, boolean isLoaded){
		setBoolean(context, ISLOADED, isLoaded);
	}
	
	public static boolean isLoaded(Context context){
		return getBoolean(context, ISLOADED, false);
	}
	
	//上一次请求锁屏数据的时间
	private static final String LAST_TIME = "last_time";
	public static void setLastRequestTime(Context context , long time){
		setLong(context, LAST_TIME, time);
	}
	
	public static long getLastRequestTime(Context context){
		return getLong(context, LAST_TIME, 0);
	}
	
	private static final String LAST_SYNC = "last_sync";
	public static void setLastSyncStrategyTime(Context context, long time){
		setLong(context, LAST_SYNC, time);
	}
	
	public static long getLastSyncStrategyTime(Context context){
		return getLong(context, LAST_SYNC, 0);
	}
	
	//记录锁屏页面显示news的index
	private static final String LAST_NEWS_INDEX = "last_news_index";
	public static void setLastNewsIndex(Context context, int index){
		setInt(context, LAST_NEWS_INDEX, index);
	}
	
	public static int getLastNewsIndex(Context context){
		return getInt(context, LAST_NEWS_INDEX, 0);
	}
	
	//记录升级用户以前的code
	private static final String VERSION_CODE = "version_code";
	public static void setVersionCode(Context context, int index){
		setInt(context, VERSION_CODE, index);
	}
	
	public static int getVersionCode(Context context){
		return getInt(context, VERSION_CODE, -1);
	}
	
	private static final String LAST_UPLOAD_BOOTSTAT = "last_upload_bootstat";
	public static void setLastUploadBootstat(Context context, long lastTime){
		setLong(context, LAST_UPLOAD_BOOTSTAT, lastTime);
	}
	
	public static long getLastUploadBootstat(Context context){
		return getLong(context, LAST_UPLOAD_BOOTSTAT, 0);
	}
	
	private static final String LAST_BOOTSTAT_DATE = "last_bootstat_date";
	public static void setLastbootstatDate(Context context, String date){
		setString(context, LAST_BOOTSTAT_DATE, date);
	}
	
	public static String getLastBootstatDate(Context context){
		return getString(context, LAST_BOOTSTAT_DATE, "1970-01-01");
	}
	
	
	private static final String INSTALL_TIME = "install_time";
	public static void setInstallTime(Context context, long time){
		setLong(context, INSTALL_TIME, time);
	}
	
	public static long getInstallTime(Context context){
		return getLong(context, INSTALL_TIME, 0);
	}
	
	private static final String  DAYS_GONE= "days_gone";
	public static void setDaysGone(Context context, int days){
		setInt(context, DAYS_GONE, days);
	}
	
	public static int getDaysGone(Context context){
		return getInt(context, DAYS_GONE, 0);
	}
	
	private static final String  H5_STATUS= "h5_status";
	public static void setH5GameStatus(Context context, boolean status){
		setBoolean(context, H5_STATUS, status);
	}
	
	public static boolean getH5GameStatus(Context context){
		return getBoolean(context, H5_STATUS, false);
	}
	
//	private static final String USER_GROUP = "user_group";
//	public static void setUserGroup(Context context, String group){
//		setString(context, USER_GROUP, group);
//	}
//	
//	public static String getUserGroup(Context context){
//		return getString(context, USER_GROUP, "");
//	}
	
//	private static final String USER_PREFERENCE = "user_preference";
//	public static void setUserPreference(Context context, String preference){
//		setString(context, USER_PREFERENCE, preference);
//	}
//	
//	public static String getUserPreference(Context context){
//		return getString(context, USER_PREFERENCE, "");
//	}
	
	private static final String USER_GROUP = "user_group";
	public static void setUserGroup(Context context, String group){
		setString(context, USER_GROUP, group);
	}
	
	public static String getUserGroup(Context context){
		return getString(context, USER_GROUP, "");
	}
	
	private static final String USER_PREFERENCE = "user_preference";
	public static void setUserPreference(Context context, String preference){
		setString(context, USER_PREFERENCE, preference);
	}
	
	public static String getUserPreference(Context context){
		return getString(context, USER_PREFERENCE, "");
	}
	
	private static final String TIME_DURATION = "time_duration";
	public static void setTimeDuration(Context context, long timeDuration){
		setLong(context, TIME_DURATION, timeDuration);
	}
	
	public static long getTimeDuration(Context context){
		return getLong(context, TIME_DURATION, 0);
	}
	
	private static final String USER_INTEREST_TIME = "user_interest_time";
	public static void setUserInterestTime(Context context, long time){
		setLong(context, USER_INTEREST_TIME, time);
	}
	
	public static long getUserInterestTime(Context context){
		return getLong(context, USER_INTEREST_TIME, 0);
	}
	
	private static final String  FIRST_LAUNCHED= "first_launched";
	public static void setFirstLaunched(Context context, boolean status){
		setBoolean(context, FIRST_LAUNCHED, status);
	}
	
	public static boolean getFirstLaunched(Context context){
		return getBoolean(context, FIRST_LAUNCHED, true);
	}
	
	public static final String IS_SHORTCUT = "is_shortcut";
	public static void setIsShortCut(Context context, boolean value){
		setBoolean(context, IS_SHORTCUT, value);
	}
	
	public static boolean isShortCut(Context context){
		return getBoolean(context, IS_SHORTCUT, false);
	}
	
	private static final String H5_UPDATE_TIME = "h5_update_time";
	public static void setH5UpdateTime(Context context, long time){
		setLong(context, H5_UPDATE_TIME, time);
	}
	
	public static long getH5UpdateTime(Context context){
		return getLong(context, H5_UPDATE_TIME, 0);
	}
	
	private static final String UPLOAD_ACT_DATA = "upload_act_data";
	public static void setUploadDataTime(Context context, long time){
		setLong(context, UPLOAD_ACT_DATA, time);
	}
	
	public static long getUploadDataTime(Context context){
		return getLong(context, UPLOAD_ACT_DATA, 0);
	}
	//	jiangyh add for upload order end
	
	private static final String LAST_OFFLINE_TIME = "last_offline_time";
	public static void setLastOfflineTime(Context context, long time){
		setLong(context, LAST_OFFLINE_TIME, time);
	}
	public static long getLastOfflineTime(Context context){
		return getLong(context, LAST_OFFLINE_TIME, 0);
	}
	
	/**
     * 记录已经生成过快捷方式的游戏
     */
    private static final String SHORTCUT_PRODUCED_BEFORE = "shortcut_produced_before";
	public static void setShortcutProducedBefore(Context context, String gameId) {
		setString(context, SHORTCUT_PRODUCED_BEFORE, gameId);
	}
	public static String getShortcutProducedBefore(Context context) {
		return getString(context, SHORTCUT_PRODUCED_BEFORE, "");
	}
	
	private static final String GAME_ICON_UPDATE_TIME = "game_icon_update_time";
	public static void setGameIconUpdateTime(Context context, long time){
		setLong(context, GAME_ICON_UPDATE_TIME, time);
	}
	
	public static long getGameIconUpdateTime(Context context){
		return getLong(context, GAME_ICON_UPDATE_TIME, 0);
	}
	
	/**
     * 向服务器同步用户信息时间戳
     */
	private static final String USER_PROFILE_UPDATE_TIME = "user_profile_update_time";
	public static void setUserProfileUpdateTime(Context context, long time){
		setLong(context, USER_PROFILE_UPDATE_TIME, time);
	}
	
	public static long getUserProfileUpdateTime(Context context){
		return getLong(context, USER_PROFILE_UPDATE_TIME, 0);
	}
	
	/**
     * 用户是否处于上海
     */
	private static final String USER_IN_SHANGHAI_FLAG = "user_in_shanghai_flag";
	public static void setUserInShanghaiFlag(Context context, boolean status){
		setBoolean(context, USER_IN_SHANGHAI_FLAG, status);
	}
	
	public static boolean getUserInShanghaiFlag(Context context){
		return getBoolean(context, USER_IN_SHANGHAI_FLAG, true);
	}
}
